package cn.qy.java.base.ch21;

/**
 * 内存可见性 demo
 */
public class Ch21_09_VisibleDemo {
	
	static volatile boolean isDone = false;
	
	static class MyThread extends Thread {
		@Override
		public void run() {
			while(!isDone) {
				
			}
			System.out.println("its done");
		}
	}
	
	public static void main(String[] args) throws InterruptedException {
		Thread thread = new MyThread();
		thread.start();
		// 确保 thread 线程启动后将 isDone 改为 true
		Thread.sleep(1000);
		isDone = true;
		thread.join();
		System.out.println("main thread over");
	}

}
